using System;
using System.Collections.Generic;
using System.ComponentModel;

using LongNet.Util;
namespace LongNet.Config
{
    /// <summary>
    /// Represents a configuration element for <see cref="T:MemcachedClient"/>. 
    /// This class cannot be inherited.
    /// </summary>
    public class MemcachedClientElement
    {
        #region Constants

        internal const string LocalName = "client";
        internal const string ServersLocalName = "servers";

        internal static class PropertyName
        {
            internal const string Name = "name";
            internal const string KeyPrefix = "keyPrefix";
            internal const string EnableCompression = "enableCompression";
            internal const string CompressionThreshold = "compressionThreshold";
        }

        #endregion

        #region Fields

        private string name = "default";
        private string keyPrefix = string.Empty;
        private bool enableCompression = true;
        private int compressionThreshold = 1024 * 10;
        private List<MemcachedServerElement> servers = null;
        private MemcachedSocketPoolElement socketPool = new MemcachedSocketPoolElement();

        #endregion

        #region Constructors

        internal MemcachedClientElement()
        {
        }

        internal MemcachedClientElement(string name, string keyPrefix, bool enableCompression, int compressionThreshold, List<MemcachedServerElement> servers, MemcachedSocketPoolElement socketPool)
        {
            this.name = name;
            this.keyPrefix = keyPrefix;
            this.enableCompression = enableCompression;
            this.compressionThreshold = compressionThreshold;
            this.servers = servers;
            this.socketPool = socketPool;
        }

        #endregion

        #region Setting Properties

        /// <summary>
        /// Gets the Name of <see cref="T:MemcachedClient"/> configuration.
        /// The value is <c>default</c> by default.
        /// </summary>
        public string Name
        {
            get { return this.name; }
            internal set
            {
                if (string.IsNullOrEmpty(value))
                    throw new ArgumentException("Name is null or empty", "Name");

                this.name = value;
            }
        }

        /// <summary>
        /// Gets the KeyPrefix of <see cref="T:MemcachedClient"/> configuration.
        /// The value is <c>string.Empty</c> by default.
        /// </summary>
        public string KeyPrefix
        {
            get { return this.keyPrefix; }
            internal set { this.keyPrefix = value; }
        }

        /// <summary>
        /// Gets the EnableCompression of <see cref="T:MemcachedClient"/> configuration.
        /// The value is <c>true</c> by default.
        /// </summary>
        public bool EnableCompression
        {
            get { return this.enableCompression; }
            internal set { this.enableCompression = value; }
        }

        /// <summary>
        /// Gets the CompressionThreshold of <see cref="T:MemcachedClient"/> configuration.
        /// The value is <c>10240</c>(10KB) by default.
        /// </summary>
        public int CompressionThreshold
        {
            get { return this.compressionThreshold; }
            internal set { this.compressionThreshold = value; }
        }

        /// <summary>
        /// Gets the Servers of <see cref="T:MemcachedClient"/> configuration.
        /// The value is an empty list by default.
        /// </summary>
        public IList<MemcachedServerElement> Servers
        {
            get { return this.servers; }
            internal set { this.servers = new List<MemcachedServerElement>(value); }
        }

        /// <summary>
        /// Gets the SocketPool of <see cref="T:MemcachedClient"/> configuration.
        /// </summary>
        public MemcachedSocketPoolElement SocketPool
        {
            get { return this.socketPool; }
            internal set { this.socketPool = value; }
        }

        #endregion
    }
}
